import request from '@/util/request'
import qs from 'qs'

export function getApplyInfo() {
  return request({
    url: '/apply-to-join/info.json',
    method: 'get',
    baseURL: process.env.VUE_APP_AJS_USER
  })
}

export function checkCompanyName(companyName) {
  return request({
    url: `company/check/name/${companyName}.json`,
    method: 'get',
    baseUrl: process.env.VUE_APP_AJS_USER
  })
}

export function checkCompanyCode(companyCode) {
  return request({
    url: `company/check/code/${companyCode}.json`,
    method: 'get',
    baseUrl: process.env.VUE_APP_AJS_USER
  })
}

export function protocol() {
  return request({
    url: 'aqs/protocol/join/detail.json',
    method: 'get',
    baseURL: process.env.VUE_APP_AJS_OTHER
  })
}

export function stepOne(data) {
  return request({
    url: '/apply-to-join/step-one.json',
    method: 'post',
    data,
    headers: { 'Content-Type': 'multipart/form-data' },
    baseURL: process.env.VUE_APP_AJS_USER
  })
}

export function listCategoryInfo() {
  return request({
    url: 'aqs/category/listCategoryInfo.json',
    method: 'get',
    baseURL: process.env.VUE_APP_AJS_MANAGER
  })
}

export function checkSellerName(sellerName) {
  return request({
    url: `apply-to-join/${sellerName}.json`,
    method: 'get',
    baseURL: process.env.VUE_APP_AJS_USER
  })
}

export function sendMobile(mobile) {
  return request({
    url: `apply-to-join/sendCode/${mobile}.json`,
    method: 'get',
    baseURL: process.env.VUE_APP_AJS_USER
  })
}

export function submit(data, headers) {
  Object.assign(headers, { 'Content-Type': 'multipart/form-data' })
  return request({
    url: 'apply-to-join.json',
    method: 'post',
    data,
    headers,
    baseURL: process.env.VUE_APP_AJS_USER
  })
}

export function code(uuid, mobile) {
  return request({
    url: `/apply-to-join/code/${uuid}.json`,
    method: 'get',
    headers: { mobile },
    baseURL: process.env.VUE_APP_AJS_USER
  })
}

export function stepTwo(data, uuid, header) {
  const headers = Object.assign({ 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8' }, header)
  return request({
    url: `/apply-to-join/step-two/${uuid}.json`,
    method: 'post',
    data: qs.stringify(data),
    headers,
    baseURL: process.env.VUE_APP_AJS_USER
  })
}
